<?php
namespace app\api\controller;

class Favorite extends BaseUser
{
	public function index()
	{
		$page = request_input('page',1);
		$data = $this->user->favorites()->order('id desc')->paginate(10);
		return cdm(200, $data, '');
	}

	public function create()
	{
		
	}

	public function save()
	{
		$forum_id = request_input('forum_id');
		$favorite = $this->user->favorites()->withTrashed()->where(['forum_id'=>$forum_id])->find();
		if($favorite){
			if($favorite['delete_time'] > 0){
				$favorite->restore();
				return cdm(200, 1, '收藏成功!');
			}else{
				$favorite->delete();
				return cdm(200, 0, '取消收藏!');
			}
		}else{
			$this->user->favorites()->save(['forum_id' => $forum_id]);
			return cdm(200, 1, '收藏成功!');
		}
	}

	public function read($id)
	{

	}

	public function edit($id)
	{
		
	}

	public function update($id)
	{

	}

	public function delete($id)
	{

	}
}